package cn.itcast.wushangxiantu.BaseAdapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import cn.itcast.wushangxiantu.R;
import cn.itcast.wushangxiantu.UserData.GuoJiaXinXi;

public class GuoJiaXinXiAdapter extends BaseAdapter {
    private Context context;
    private GuoJiaXinXi guoJiaXinXi;
    private ViewHolder viewHolder;

    @Override
    public int getCount() {
        if (null == guoJiaXinXi) {
            return 0;
        } else {
            return guoJiaXinXi.getList().size();
        }
    }

    public GuoJiaXinXiAdapter(Context context) {
        this.context = context;
    }

    public GuoJiaXinXi getGuoJiaXinXi() {
        return guoJiaXinXi;
    }

    public void setGuoJiaXinXi(GuoJiaXinXi guoJiaXinXi) {
        this.guoJiaXinXi = guoJiaXinXi;
        notifyDataSetChanged();
    }

    @Override
    public Object getItem(int i) {
        return guoJiaXinXi.getList().get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        view = View.inflate(context, R.layout.adapter_guojiaxinxi, null);
        viewHolder = new ViewHolder(view);
        viewHolder.tvTime.setText(guoJiaXinXi.getList().get(i).getTime());
        viewHolder.tvTitle.setText(guoJiaXinXi.getList().get(i).getContent());
        return view;
    }

    class ViewHolder {
        public View rootView;
        public TextView tvTitle;
        public TextView tvTime;

        public ViewHolder(View rootView) {
            this.rootView = rootView;
            this.tvTitle = (TextView) rootView.findViewById(R.id.tvTitle);
            this.tvTime = (TextView) rootView.findViewById(R.id.tvTime);
        }
    }
}
